package com.boot.ys.mybatisplus.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.boot.ys.mybatisplus.entity.User;
import com.boot.ys.mybatisplus.entity.vo.IdCardVO;
import com.boot.ys.mybatisplus.mapper.UserMapper;
import com.boot.ys.mybatisplus.result.Result;
import com.boot.ys.mybatisplus.service.UserService;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author Yang Sheng
 * @since 2021-10-25
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户表控制器")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 数字藏品里面的接口  调用天眼的实名验证
     *
     * @param arr
     */
    @PostMapping("/IdCardValidate")
    public Result IdCardValidate(@RequestBody IdCardVO idCard) throws IOException {

        userService.IdCardValidate(idCard);


        return Result.ok();
    }


    @PostMapping("/testArr")
    @ApiOperation("测试数组")
    public void testArr(String[] arr) {
        String[] arr1 = arr;

        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
        System.out.println(arr.length);

    }

//    @PostMapping("/testEnptyArr")
//    @ApiOperation("测试实体类数组")
//    public void testArray(@RequestBody User user){
//        String[] arr = user.getArr();
//
//        for (int i=0 ; i<arr.length;i++ ) {
//            System.out.println(arr[i]);
//        }
//        System.out.println(arr.length);
//
//    }


    @PostMapping("/getAll")
    @ApiOperation("获取全部用户")
    public List<User> getAll() {
        List<User> all = userService.getAll();
        return all;
    }

    @PostMapping("/updateToTab")
    @ApiOperation("同时更新两张表")
    public Boolean updateToTab() {
        Boolean aBoolean = userService.updateToTab();
        return aBoolean;
    }

    @PostMapping("/update")
    @ApiOperation("更新数据")
    public Result updateUser(@RequestBody User user) {
        int i = userService.updateUser(user);

        return Result.ok(i);
    }


}
